--BO工序工艺信息
alter PROCEDURE getBoProcessDetail @begingmt_create DATETIME,
                                    @endgmt_create DATETIME,
                                    @PageIndex INT,
                                    @PageSize INT,
                                    @TotalCount INT OUTPUT,
                                    @BoStatus NVARCHAR(255),
                                    @item_code NVARCHAR(255),
                                    @khdm VARCHAR(50),
                                    @team NVARCHAR(255)
AS
BEGIN
    SET NOCOUNT ON;

    -- 计算分页的起始位置
    DECLARE @Offset INT = (@PageIndex - 1) * @PageSize;
--------------------------------------------------------------------------------------------
    SELECT a.batch_number                            AS 工单号,
           mes_type.name                             AS MES订单类型,
           a.item_code                               AS Item_Code,
           a.customer_code                           AS 客户代码,
           a.customer_name                           AS 客户名称,
           a.mes_order_create_time                   AS 开单日期,
           a.gmt_modified                            AS 工单修改时间,
           c.sn                                      AS 序号,
           c.print_surface                           AS 印面,
           c.color_one                               AS 颜色名1,
           c.color_two                               AS 颜色名2,
           c.print_num                               AS 印数,
           c.paper_used_num                          AS 净纸用料数,
           c.loss_num                                AS 损耗数,
           c.tasks_num                               AS 任务数,
           c.material_total                          AS 领料合计,
           c.chrominance                             AS 色度,
           c.area                                    AS 面积,
           c.gmt_create                              AS 创建时间,
           c.gmt_modified                            AS 修改时间,
           c.is_del                                  AS 逻辑删除,
           c.color_remark                            AS 颜色备注,
           c.color_manuscript_code                   AS 色稿编号,
           c.process_card_no                         AS 工艺卡编号,
           c.printing_ink_no                         AS 油墨编号,
           c.uv_printing_ink_no                      AS UV油墨编号,
           c.printed_surface                         AS 印刷面,
           c.process_line_info                       AS 产线信息,
           c.custom_fields                           AS 自定义字段json字符串,
           c.paper_open                              AS 纸张开数,
           c.[color_manuscript_storage_location    ] AS 色稿库位,
           c.loss_num1                               AS 一次损耗,
           c.tasks_num1                              AS 一次任务数,
           c.material_total1                         AS 一次领料合计,
           b.process_name                            AS 工序名称
    FROM mes_batch_order a
             LEFT JOIN
         mes_bo_process b ON a.id = b.bo_id
             LEFT JOIN
         mes_bo_process_detail c ON c.bo_process_id = b.id
             left join sys_dict mes_type on a.mes_order_type = mes_type.value and mes_type.type = 'MES_ORDER_TYPE'


------------------------------------------------------------------------------------------------------


    WHERE (@begingmt_create IS NULL OR a.gmt_create >= @begingmt_create)
      AND (@endgmt_create IS NULL OR a.gmt_create <= @endgmt_create)
      AND (@BoStatus IS NULL OR a.status in (SELECT value FROM STRING_SPLIT(@BoStatus, ',')))
      AND (@item_code IS NULL OR a.item_code = @item_code)
      AND (@khdm IS NULL OR a.customer_code = @khdm)
      and (@team IS NULL OR a.team = @team)

    order by a.gmt_create desc
    OFFSET @Offset ROWS FETCH NEXT @PageSize ROWS ONLY;

    SELECT @TotalCount = COUNT(1)

    ---------------------------------------------------------------------

    FROM mes_batch_order a
             LEFT JOIN
         mes_bo_process b ON a.id = b.bo_id
             LEFT JOIN
         mes_bo_process_detail c ON c.bo_process_id = b.id
             left join sys_dict mes_type on a.mes_order_type = mes_type.value and mes_type.type = 'MES_ORDER_TYPE'
    -------------------------------------------

    WHERE (@begingmt_create IS NULL OR a.gmt_create >= @begingmt_create)
      AND (@endgmt_create IS NULL OR a.gmt_create <= @endgmt_create)
      AND (@BoStatus IS NULL OR a.status in (SELECT value FROM STRING_SPLIT(@BoStatus, ',')))
      AND (@item_code IS NULL OR a.item_code = @item_code)
      AND (@khdm IS NULL OR a.customer_code = @khdm)
      and (@team IS NULL OR a.team = @team)

END